package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.BaiCheck;
import com.ruoyi.system.service.IBaiCheckService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 每日打卡Controller
 * 
 * @author saruri
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/check")
public class BaiCheckController extends BaseController
{
    @Autowired
    private IBaiCheckService baiCheckService;

    /**
     * 查询今日是否打卡
     */
    @GetMapping("/checkTodayRecord")
    public boolean checkTodayRecord() {
        long userId=SecurityUtils.getUserId();
        return baiCheckService.checkTodayRecord(userId);
    }

    /**
     * 查询每日打卡列表
     */
    @RequiresPermissions("system:check:list")
    @GetMapping("/list")
    public TableDataInfo list(BaiCheck baiCheck)
    {
        startPage();
        List<BaiCheck> list = baiCheckService.selectBaiCheckList(baiCheck);
        return getDataTable(list);
    }

    /**
     * 导出每日打卡列表
     */
    @RequiresPermissions("system:check:export")
    @Log(title = "每日打卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaiCheck baiCheck)
    {
        List<BaiCheck> list = baiCheckService.selectBaiCheckList(baiCheck);
        ExcelUtil<BaiCheck> util = new ExcelUtil<BaiCheck>(BaiCheck.class);
        util.exportExcel(response, list, "每日打卡数据");
    }

    /**
     * 获取每日打卡详细信息
     */
    @RequiresPermissions("system:check:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baiCheckService.selectBaiCheckById(id));
    }

    /**
     * 新增每日打卡
     */
    @RequiresPermissions("system:sci:add")
    @Log(title = "每日打卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaiCheck baiCheck)
    {
        System.out.println("传参数据");
        System.out.println(baiCheck);
        baiCheck.setUserId(SecurityUtils.getUserId());
        return toAjax(baiCheckService.insertBaiCheck(baiCheck));
    }

    /**
     * 修改每日打卡
     */
    @RequiresPermissions("system:check:edit")
    @Log(title = "每日打卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaiCheck baiCheck)
    {
        return toAjax(baiCheckService.updateBaiCheck(baiCheck));
    }

    /**
     * 删除每日打卡
     */
    @RequiresPermissions("system:check:remove")
    @Log(title = "每日打卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baiCheckService.deleteBaiCheckByIds(ids));
    }
}
